--
-- Author: yawei.zhu
-- Date: 2018-07-18 15:42:22
--
local Equip = require("app.public.dao.Equip")

local fileName = string.getModeName(...)
local ClassRef = class(fileName)

function ClassRef:ctor(ret)
	if ret then
		self:read(ret)
	end
end

function ClassRef:read(ret)
	self.baseInfo = UserBaseInfo.new(ret.baseinfo)

	-- 格子强化等级
	self.equipGridStrengths = {}
	for _, data in ipairs(ret.equipGrids) do
		self.equipGridStrengths[ data.location ] = data.level
	end
	-- dump(ret.equipGrids)

	-- 属性
	self.showAttrList = {}
	local prop = ret.prop
	local propShowConfs = GD:querypropShow()
	local classTemp = tostring( self.baseInfo.classID )
    for _, v in ipairs(propShowConfs) do
		if string.find( v.roleSuit, classTemp ) then
			local conf = GD:getPropConfigByName(v.propName)
			local format = 1
			if conf then
				format = tonumber(conf.format)
			end
			local propValue = 0
			if v.propName == "baseattackspeed" then
				propValue = GD:queryProBase(classTemp).baseattackspeed
			else
				propValue = rawget(prop, v.propName) or 0
			end
			table.insert( self.showAttrList, { v.propName, propValue, format} )
        end
	end
    -- dump(self.showAttrList)

    -- 装备
	local equips = {}
	for _, data in ipairs(ret.equips) do
		local equip = Equip.new()
        equip:read(data)
        table.insert(equips, equip)
	end
	self.equips = equips

	local sinfos = {}
	for _, data in ipairs(ret.sinfos) do
		local value = {}
		value.id = data.id
		value.value = data.value
		table.insert(sinfos, value)
	end
	self.sinfos = sinfos

	self.achvPoint = ret.achvPoint
	self.mountNum = ret.mountNum
	self.partnerNum = ret.partnerNum
end

return ClassRef

